package com.example.myandroidtest.ui.aidl;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myandroidtest.databinding.ActivityAidlBinding;

public class AidlActivity extends AppCompatActivity {

    ActivityAidlBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityAidlBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initView();
    }

    private ServiceConnection connection = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {

        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };

    private void initView() {
        binding.btnBind.setOnClickListener(v -> {
            Intent intent = new Intent();
            ComponentName componentName = new ComponentName("com.buerke.myandroidassist",
                    "com" + ".buerke" + ".myandroidassist.service.ServerService");
            intent.setComponent(componentName);

            bindService(intent, connection, BIND_AUTO_CREATE);
        });
    }
}